package com.echo.code.thread.mode.worker;

import static java.util.concurrent.ThreadLocalRandom.current;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.IntStream;

/**
 * TestCase Created by baiyap on 2018/9/24.
 */
public class TestCase {

  public static void main(String[] args) {
    final Channel channel = new Channel(5);
    AtomicInteger workNo = new AtomicInteger();
    IntStream.range(0, 8).forEach(i ->
        new Thread(() -> {
          while (true) {
            try {
              channel.offerWork(new ConcreteWork(workNo.getAndIncrement()));
              TimeUnit.SECONDS.sleep(current().nextInt(10));
            } catch (Exception e) {
            }
          }
        }).start()
    );
  }
}
